package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.ErpCustomerDto;
import com.nuoniu.sibanyun.entity.erp.ErpCustomer;
import com.nuoniu.sibanyun.service.erp.IErpCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 白强
 * @since 2021-01-23
 */
@RestController
@RequestMapping("/erp/customer")
@Api(value = "ERP_客户档案", tags = "ERP_客户档案")
public class ErpCustomerController extends BaseController {

    @Autowired
    private IErpCustomerService erpCustomerService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public HttpResult<List<ErpCustomer>> page(ErpCustomerDto erpCustomerDto) {
        return HttpResult.ok(erpCustomerService.pageList(erpCustomerDto));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public HttpResult save(@RequestBody ErpCustomer ErpCustomer) {
        erpCustomerService.saveErpCustomer(ErpCustomer);
        return HttpResult.ok();
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
    public HttpResult delete(Integer id) {
        erpCustomerService.delete(id);
        return HttpResult.ok();
    }

    @ApiOperation("导入数据")
    @PostMapping("importData")
    public HttpResult importData(MultipartFile file) throws IOException {
        erpCustomerService.importData(file);
        return HttpResult.ok();
    }
}
